package cn.com.servlet;

import cn.com.bean.TraineeBean;
import cn.com.dao.impl.TraineeDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

public class RegistDataServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        TraineeBean user = (TraineeBean) session.getAttribute("user");
        TraineeDaoImpl userdao = new  TraineeDaoImpl();
        PrintWriter out = response.getWriter();
        boolean b = userdao.insert(user);
        if (b == true) {
            out.print("success");
			/*out.print("<script type = 'text/javascript'>");
			out.print("window.location = 'login.jsp';");
			out.print("</script>");*/
        }else{
            out.print("defult");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
